package com.work.intelligent_transportation2;

import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.view.MenuItem;
import android.widget.FrameLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.drawerlayout.widget.DrawerLayout;

import com.google.android.material.navigation.NavigationView;
import com.work.intelligent_transportation2.fragment.CarSystemFragment;
import com.work.intelligent_transportation2.fragment.EnvironmentWeatherSystemFragment;
import com.work.intelligent_transportation2.fragment.FeedbackSystemFragment;
import com.work.intelligent_transportation2.fragment.ParkingLotSystemFragment;
import com.work.intelligent_transportation2.fragment.RoadSystemFragment;
import com.work.intelligent_transportation2.fragment.TrafficLightsSystemFragment;
import com.work.intelligent_transportation2.fragment.TravelSystemFragment;

public class HomeActivity extends AppCompatActivity {

    private DrawerLayout HomeDrawerLayout;
    private FrameLayout homeFl;
    private TextView homeTextView;
    private NavigationView homeNavigation;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_home);
        initFragment();
        initView();
        homeNavigation.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
            @Override
            public boolean onNavigationItemSelected(@NonNull MenuItem item) {
                item.setCheckable(true);
                switch (item.getItemId()) {
                    case R.id.itemCarSystem:
                        homeTextView.setText("小车子系统");
                        getFragmentManager().beginTransaction().replace(R.id.home_fl, new CarSystemFragment()).commit();
                        break;
                    case R.id.itemTrafficLightsSystem:
                        homeTextView.setText("红绿灯子系统");
                        getFragmentManager().beginTransaction().replace(R.id.home_fl, new TrafficLightsSystemFragment()).commit();
                        break;
                    case R.id.itemEnvironmentWeatherSystem:
                        homeTextView.setText("环境和天气子系统");
                        getFragmentManager().beginTransaction().replace(R.id.home_fl, new EnvironmentWeatherSystemFragment()).commit();
                        break;
                    case R.id.itemParkingLotSystem:
                        homeTextView.setText("停车场子系统");
                        getFragmentManager().beginTransaction().replace(R.id.home_fl, new ParkingLotSystemFragment()).commit();
                        break;
                    case R.id.itemRoadSystem:
                        homeTextView.setText("道路子系统");
                        getFragmentManager().beginTransaction().replace(R.id.home_fl, new RoadSystemFragment()).commit();
                        break;
                    case R.id.itemTravelSystem:
                        homeTextView.setText("旅游子系统");
                        getFragmentManager().beginTransaction().replace(R.id.home_fl, new TravelSystemFragment()).commit();
                        break;
                    case R.id.itemFeedbackSystem:
                        homeTextView.setText("用户及意见");
                        getFragmentManager().beginTransaction().replace(R.id.home_fl, new FeedbackSystemFragment()).commit();
                        break;
                }
                HomeDrawerLayout.closeDrawers();
                return true;
            }
        });

    }

    private void initView() {
        HomeDrawerLayout = findViewById(R.id.Home_DrawerLayout);
        homeFl = findViewById(R.id.home_fl);
        homeTextView = (TextView) findViewById(R.id.home_TextView);
        homeNavigation = (NavigationView) findViewById(R.id.home_navigation);
    }

    private void initFragment() {
        CarSystemFragment carSystemFragment = new CarSystemFragment();
        FragmentManager fragmentManager = getFragmentManager();
        FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
        fragmentTransaction.add(R.id.home_fl, carSystemFragment);
        fragmentTransaction.commit();
    }


}